/***************************************************************************//**
 * @file FDM/FDM_Main.h
 * @author  Marek M. Cel <marekcel@mscsim.org>
 *
 * @section LICENSE
 *
 * Copyright (C) 2014 Marek M. Cel
 *
 * This file is part of MScSim. You can redistribute and modify it under
 * the terms of GNU General Public License as published by the Free Software
 * Foundation; either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.
 * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Further information about the GNU General Public License can also be found
 * on the world wide web at http://www.gnu.org.
 ******************************************************************************/
#ifndef FDM_MAIN_H
#define FDM_MAIN_H

////////////////////////////////////////////////////////////////////////////////

#include <MSc_FDM.h>

#include "FDM_DataInp.h"
#include "FDM_DataOut.h"

#include "FDM_Controls.h"
#include "FDM_Environment.h"
#include "FDM_Recording.h"

////////////////////////////////////////////////////////////////////////////////

#define MSCSIM_TIME_STEP_MIN    0.001
#define MSCSIM_TIME_STEP_INT    0.010
#define MSCSIM_TIME_STEP_MAX    0.100

////////////////////////////////////////////////////////////////////////////////

/** */
class FDM_Main
{
public:

    /** */
    FDM_Main();

    /** */
    virtual ~FDM_Main();

    /** */
    void init( const FDM_DataInp &dataInp, FDM_DataOut &dataOut );

    /** */
    void update( double timeStep, const FDM_DataInp &dataInp, FDM_DataOut &dataOut );

protected:

    MSc_FDM *m_fdm;             ///< flight dynamics model

    FDM_Controls    *m_ctrl;    ///< flight controls model
    FDM_Environment *m_envr;    ///< environment model
    FDM_Recording   *m_rcrd;    ///< flight recording and replaying

    double m_timeStepSim;       ///< [s] simulation time step
    double m_timeStepInt;       ///< [s] integration time step

    int m_timeIntSteps;         ///< number of time integration steps to be performed during one simulation step. This value is dependent on simulation time step.

    /** */
    void anteLoop();

    /** */
    void anteStep();

    /** */
    void postStep();

    /** */
    void postLoop();

    /**
     * This function computes and updates simulation and integrations
     * time steps due MSCFDM_TIME_STEP_MIN and MSCFDM_TIME_STEP_MAX values.
     * @param simulation time step [s]
     */
    void computeTimeStep( double timeStep );

private:

    /** Using this constructor is forbidden. */
    FDM_Main( const FDM_Main & ) {}
};

////////////////////////////////////////////////////////////////////////////////

#endif // FDM_MAIN_H
